var builder = WebApplication.CreateBuilder(args);


builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseStaticFiles(); // 添加静态文件支持

// 添加根目录映射指向首页
app.MapGet("/", () => Results.Redirect("/index.html"));

// 中医药科普短视频自动生成API
app.MapGet("/herbvideo/{herbName}", (string herbName) =>
{
    // 这里应该实现实际的业务逻辑，目前返回示例数据
    // 实际实现中，应该查询数据库或调用外部API来获取草药信息
    if (string.IsNullOrWhiteSpace(herbName))
    {
        return Results.Json(new { error = "无效中草药名称" });
    }

    // 示例：黄芪的返回结果
    if (herbName == "黄芪")
    {
        var result = new {
            title = "补气圣药黄芪，每天一泡超养人！",
            script = new[] {
                "你知道吗？",
                "黄芪是中医补气第一药！",
                "李时珍说它能‘固表止汗’",
                "现代研究：增强免疫力！",
                "泡水喝，简单又有效！",
                "你用过黄芪吗？"
            },
            keyFacts = new[] {
                "【《本草纲目》】黄芪味甘，性微温，主痈疽久败疮，排脓止痛。",
                "【《中国药典》2020版】黄芪为豆科植物蒙古黄芪或膜荚黄芪的干燥根。",
                "【《中药学》教材】黄芪多糖可提升T细胞活性，辅助肿瘤康复。"
            },
            visualSuggestions = new[] {
                new {
                    text = "你知道吗？",
                    scene = "水墨背景缓缓浮现黄芪药材特写，镜头缓慢推进",
                    effect = "毛笔字迹逐笔写出"
                },
                new {
                    text = "黄芪是中医补气第一药！",
                    scene = "古代医馆内老医师手持黄芪根，微笑点头",
                    effect = "金色光晕环绕药材"
                },
                new {
                    text = "李时珍说它能‘固表止汗’",
                    scene = "《本草纲目》古籍翻页，重点句高亮发光",
                    effect = "纸页自动翻动 + 水墨晕染"
                },
                new {
                    text = "现代研究：增强免疫力！",
                    scene = "显微镜下免疫细胞活跃动画 + 黄芪分子结构飘出",
                    effect = "粒子流动 + 科技蓝光效"
                },
                new {
                    text = "泡水喝，简单又有效！",
                    scene = "玻璃杯中黄芪片缓缓沉底，热水泛起淡黄色汤色",
                    effect = "热气升腾 + 光斑闪烁"
                },
                new {
                    text = "你用过黄芪吗？",
                    scene = "年轻女性端杯微笑，背景虚化为多个用户点赞评论弹幕",
                    effect = "弹幕飞入 + 右下角二维码浮现"
                }
            },
            audio = new {
                bgm = "古筝曲《流水》轻柔版",
                sfx = new[] { "水滴落杯声", "古籍翻页声" }
            }
        };
        return Results.Json(result);
    }
    
    // 对于其他草药，暂时返回错误信息
    return Results.Json(new { error = "无效中草药名称" });
})
.WithName("GetHerbVideo")
.WithOpenApi();

app.Run();